package com.ce.socket;

import org.apache.log4j.Logger;

public abstract class BsSocketPool {
	private static Logger log = Logger.getLogger(BsSocketPool.class);
	protected static final Integer ZERO       = new Integer( 0 );
	protected String poolName;
	protected static final long MAX_RETRY_DELAY = 10 * 60 * 1000;  // max of 10 minute delay for fall off

	protected boolean initialized        = false;

	// initial, min and max pool sizes
	protected int poolMultiplier        = 1;
	protected int initConn              = 1;
	protected int minConn               = 1;
	protected int maxConn               = 5;
	protected long maxIdle              = 1000 * 60 * 1;		// max idle time for avail sockets
	protected long maxBusyTime          = 1000 * 30;			// max idle time for avail sockets
	protected long daemonSleep           = 1000 * 3;			// maintenance thread sleep time
	protected int socketTO              = 1000 * 3;			// default timeout of socket reads
	protected int socketConnectTO       = 1000 * 3;	        // default timeout of socket connections
	protected boolean aliveCheck        = true;				// default to not check each connection for being alive
	protected boolean poolIsAvail       = true;			
	protected boolean nagle             = true;				// enable/disable Nagle's algorithm
	// list of all servers
	protected String server;
	protected Class<?> socketCls;
	
	public BsSocketPool(String server) {
		this.server = server;
		this.poolName = server+"_pool";
	}
	public BsSocketPool(String server, Class<?> socketCls) {
		this.server = server;
		this.socketCls = socketCls;
	}
	
	public BsSocketPool(String server, String poolName, Class<?> socketCls) {
		this.server = server;
		this.poolName = server+"<->"+poolName;
		this.socketCls = socketCls;
	}

	public int getPoolMultiplier() {
		return poolMultiplier;
	}

	public void setPoolMultiplier(int poolMultiplier) {
		this.poolMultiplier = poolMultiplier;
	}

	public int getInitConn() {
		return initConn;
	}

	public void setInitConn(int initConn) {
		this.initConn = initConn;
	}

	public int getMinConn() {
		return minConn;
	}

	public void setMinConn(int minConn) {
		this.minConn = minConn;
	}

	public int getMaxConn() {
		return maxConn;
	}

	public void setMaxConn(int maxConn) {
		this.maxConn = maxConn;
	}

	public long getMaxIdle() {
		return maxIdle;
	}

	public void setMaxIdle(long maxIdle) {
		this.maxIdle = maxIdle;
	}

	public int getSocketTO() {
		return socketTO;
	}

	public void setSocketTO(int socketTO) {
		this.socketTO = socketTO;
	}

	public int getSocketConnectTO() {
		return socketConnectTO;
	}

	public void setSocketConnectTO(int socketConnectTO) {
		this.socketConnectTO = socketConnectTO;
	}

	public boolean isAliveCheck() {
		return aliveCheck;
	}

	public void setAliveCheck(boolean aliveCheck) {
		this.aliveCheck = aliveCheck;
	}

	public boolean isAvail() {
		return this.poolIsAvail;
	}

	public boolean isNagle() {
		return nagle;
	}

	public void setNagle(boolean nagle) {
		this.nagle = nagle;
	}

	public String getServer() {
		return server;
	}

	public void setServer(String server) {
		this.server = server;
	}

	public String getPoolName() {
		return poolName;
	}

	public boolean isInitialized() {
		return initialized;
	}
	
	
	
}
